<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<title>Dissasemble: src/process/elfProcess/headerProcess.c Source File</title>

<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<script type="text/javascript">
  $(document).ready(initResizable);
</script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/search.js"></script>
<script type="text/javascript">
  $(document).ready(function() { searchBox.OnSelectItem(0); });
</script>

</head>
<body>
<div id="top"><!-- do not remove this div! -->


<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  
  <td id="projectlogo"><img alt="Logo" src="Hopper_v3.png"/></td>
  
  
  <td style="padding-left: 0.5em;">
   <div id="projectname">Dissasemble
   &#160;<span id="projectnumber">1.0</span>
   </div>
   <div id="projectbrief">This project receives as input a file.o and displays the assembly code for that object.</div>
  </td>
  
  
  
 </tr>
 </tbody>
</table>
</div>

<!-- Generated by Doxygen 1.7.6.1 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'Search');
</script>
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li><a href="annotated.html"><span>Data&#160;Structures</span></a></li>
      <li class="current"><a href="files.html"><span>Files</span></a></li>
      <li>
        <div id="MSearchBox" class="MSearchBoxInactive">
        <span class="left">
          <img id="MSearchSelect" src="search/mag_sel.png"
               onmouseover="return searchBox.OnSearchSelectShow()"
               onmouseout="return searchBox.OnSearchSelectHide()"
               alt=""/>
          <input type="text" id="MSearchField" value="Search" accesskey="S"
               onfocus="searchBox.OnSearchFieldFocus(true)" 
               onblur="searchBox.OnSearchFieldFocus(false)" 
               onkeyup="searchBox.OnSearchFieldChange(event)"/>
          </span><span class="right">
            <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
          </span>
        </div>
      </li>
    </ul>
  </div>
  <div id="navrow2" class="tabs2">
    <ul class="tablist">
      <li><a href="files.html"><span>File&#160;List</span></a></li>
      <li><a href="globals.html"><span>Globals</span></a></li>
    </ul>
  </div>
</div>
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
  initNavTree('header_process_8c.html','');
</script>
<div id="doc-content">
<div class="header">
  <div class="headertitle">
<div class="title">src/process/elfProcess/headerProcess.c</div>  </div>
</div><!--header-->
<div class="contents">
<a href="header_process_8c.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
<a name="l00002"></a>00002 <span class="comment"> ============================================================================</span>
<a name="l00003"></a>00003 <span class="comment"> Name        : headerProcess.c</span>
<a name="l00004"></a>00004 <span class="comment"> Author      :</span>
<a name="l00005"></a>00005 <span class="comment"> Version     :  1</span>
<a name="l00006"></a>00006 <span class="comment"> Copyright   : Your copyright notice</span>
<a name="l00007"></a>00007 <span class="comment"> Description : Processing the content of each of the sections of the file to be disassembled</span>
<a name="l00008"></a>00008 <span class="comment"> ============================================================================</span>
<a name="l00009"></a>00009 <span class="comment"> */</span>
<a name="l00010"></a>00010 <span class="preprocessor">#include &quot;<a class="code" href="header_process_8h.html">headerProcess.h</a>&quot;</span>
<a name="l00011"></a>00011 <span class="preprocessor">#include &lt;<a class="code" href="config_8h.html">config.h</a>&gt;</span>
<a name="l00012"></a>00012 <span class="preprocessor">#include &lt;stdio.h&gt;</span>
<a name="l00013"></a>00013 <span class="preprocessor">#include &lt;stdlib.h&gt;</span>
<a name="l00014"></a>00014 <span class="preprocessor">#include &lt;sys/types.h&gt;</span>
<a name="l00015"></a>00015 <span class="preprocessor">#include &lt;unistd.h&gt;</span>
<a name="l00016"></a>00016 <span class="preprocessor">#include &quot;<a class="code" href="decode_8h.html">process/decode/decode.h</a>&quot;</span>
<a name="l00017"></a>00017 <span class="preprocessor">#include &lt;<a class="code" href="my_lib_8h.html">myLib.h</a>&gt;</span>
<a name="l00018"></a>00018 
<a name="l00019"></a><a class="code" href="header_process_8c.html#a1f0e224fa59a7f99fdef842b0efb7728">00019</a> <span class="preprocessor">#define HEADER_NAME_TEXT &quot;.text&quot;</span>
<a name="l00020"></a>00020 <span class="preprocessor"></span>
<a name="l00021"></a>00021 <span class="keywordtype">char</span> <a class="code" href="header_process_8c.html#a9832a2fd05088ded2ec732fa0656dfca" title="Function that processes the text contained within a section of the file.">processText</a>(GElf_Shdr shdr, Elf* e, <span class="keywordtype">size_t</span> shstrndx, <span class="keywordtype">int</span> <a class="code" href="my_obj_dump_8c.html#a6f8059414f0228f0256115e024eeed4b" title="Pointer to binary file.">fd</a>); 
<a name="l00022"></a>00022 
<a name="l00025"></a><a class="code" href="structs__header_process.html">00025</a> <span class="keyword">typedef</span> <span class="keyword">struct</span>
<a name="l00027"></a>00027 {
<a name="l00028"></a><a class="code" href="structs__header_process.html#a5ac083a645d964373f022d03df4849c8">00028</a>         <span class="keywordtype">char</span> *<a class="code" href="structs__header_process.html#a5ac083a645d964373f022d03df4849c8" title="Section Name.">name</a>; 
<a name="l00029"></a><a class="code" href="structs__header_process.html#a0238e3e52699a2c28c345cb6bb805ef1">00029</a>         char (*func)(GElf_Shdr shdr, Elf* e, <span class="keywordtype">size_t</span> shstrndx, <span class="keywordtype">int</span> <a class="code" href="my_obj_dump_8c.html#a6f8059414f0228f0256115e024eeed4b" title="Pointer to binary file.">fd</a>); 
<a name="l00030"></a>00030 } <a class="code" href="structs__header_process.html" title="structure containing the name and function of each section to disassemble">s_headerProcess</a>;
<a name="l00031"></a>00031 
<a name="l00032"></a><a class="code" href="header_process_8c.html#aa3d3410182a503bc7302d19f7c6c3119">00032</a> <a class="code" href="structs__header_process.html" title="structure containing the name and function of each section to disassemble">s_headerProcess</a> <a class="code" href="header_process_8c.html#aa3d3410182a503bc7302d19f7c6c3119" title="Array of header functions.">headerFunctions</a>[] = 
<a name="l00033"></a>00033 {
<a name="l00034"></a>00034 { <a class="code" href="header_process_8c.html#a1f0e224fa59a7f99fdef842b0efb7728">HEADER_NAME_TEXT</a>, <a class="code" href="header_process_8c.html#a9832a2fd05088ded2ec732fa0656dfca" title="Function that processes the text contained within a section of the file.">processText</a> },
<a name="l00035"></a>00035 { 0, 0 } };
<a name="l00036"></a>00036 
<a name="l00044"></a><a class="code" href="header_process_8h.html#a689841adf939e25049d03bb3bd395468">00044</a> <span class="keywordtype">char</span> <a class="code" href="header_process_8c.html#a5de22d81fbbb97dc663c2b87c27a6f48">processHeader</a>(GElf_Shdr shdr, Elf* e, <span class="keywordtype">size_t</span> shstrndx, <span class="keywordtype">int</span> <a class="code" href="my_obj_dump_8c.html#a6f8059414f0228f0256115e024eeed4b" title="Pointer to binary file.">fd</a>)
<a name="l00045"></a>00045 {
<a name="l00046"></a>00046         <span class="keywordtype">char</span> *name;
<a name="l00047"></a>00047 
<a name="l00048"></a>00048         <a class="code" href="structs__header_process.html" title="structure containing the name and function of each section to disassemble">s_headerProcess</a> *pFunc = <a class="code" href="header_process_8c.html#aa3d3410182a503bc7302d19f7c6c3119" title="Array of header functions.">headerFunctions</a>;
<a name="l00049"></a>00049         <span class="keywordflow">while</span> (pFunc-&gt;<a class="code" href="structs__header_process.html#a5ac083a645d964373f022d03df4849c8" title="Section Name.">name</a> != 0)
<a name="l00050"></a>00050         {
<a name="l00051"></a>00051 
<a name="l00052"></a>00052                 <span class="keywordflow">if</span> ((name = elf_strptr(e, shstrndx, shdr.sh_name)) == NULL )
<a name="l00053"></a>00053                 {
<a name="l00054"></a>00054                         <a class="code" href="debug_8c.html#a8ded31085b483d44dbeb3adbecd2debf" title="Displays the error message.">PRINT_ERROR</a>(<span class="stringliteral">&quot;elf_strptr () failed : % s . &quot;</span>, elf_errmsg(-1));
<a name="l00055"></a>00055                         <span class="keywordflow">return</span> <a class="code" href="debug_8h.html#ae4a97f0d170bc8dc771aac6c4f38ad1d" title="Response code when a process was run efficiently.">STATUS_ERROR</a>;
<a name="l00056"></a>00056                 }
<a name="l00057"></a>00057                 <a class="code" href="debug_8h.html#a1b7e26bb727a722ca100ed856b4e1d98" title="Print Debug.">PRINT_DEBUG</a>(<a class="code" href="debug_8h.html#a41d588ee907c299c7a790964deeef02d" title="Debug all process.">DEBUG_ALL</a>, <span class="stringliteral">&quot;Section %s\n&quot;</span>, name);
<a name="l00058"></a>00058                 <span class="comment">//PRINT_DEBUG(&quot;   size %x\n&quot;, shdr.sh_size);</span>
<a name="l00059"></a>00059                 <span class="comment">//PRINT_DEBUG(&quot;   offs %x\n&quot;, shdr.sh_offset);</span>
<a name="l00060"></a>00060                 <span class="keywordflow">if</span> (strcmp(name, headerFunctions-&gt;<a class="code" href="structs__header_process.html#a5ac083a645d964373f022d03df4849c8" title="Section Name.">name</a>) == 0)
<a name="l00061"></a>00061                 {
<a name="l00062"></a>00062                         headerFunctions-&gt;<a class="code" href="structs__header_process.html#a0238e3e52699a2c28c345cb6bb805ef1" title="Function to be process.">func</a>(shdr, e, shstrndx, fd);
<a name="l00063"></a>00063                 }
<a name="l00064"></a>00064                 pFunc++;
<a name="l00065"></a>00065         }
<a name="l00066"></a>00066         <span class="keywordflow">return</span> <a class="code" href="debug_8h.html#ae56fdb340b23940f7a64ed2e37c1774a" title="Response code when a process has performed an error in its execution.">STATUS_SUCCESS</a>;
<a name="l00067"></a>00067 }
<a name="l00068"></a>00068 
<a name="l00069"></a><a class="code" href="header_process_8c.html#a3c0994146b1bef939dee3fe64f6dce28">00069</a> <span class="preprocessor">#define RAW_PRINT_LENGTH 16 ///&lt;Raw print length</span>
<a name="l00070"></a>00070 <span class="preprocessor"></span>
<a name="l00076"></a><a class="code" href="header_process_8c.html#ad24288bd8f64a0089255ac61b93c4ecb">00076</a> <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> <a class="code" href="header_process_8c.html#ad24288bd8f64a0089255ac61b93c4ecb" title="Reads the binary contents of a byte of section established.">readBinHeaderByte</a>(GElf_Shdr shdr, <span class="keywordtype">int</span> <a class="code" href="my_obj_dump_8c.html#a6f8059414f0228f0256115e024eeed4b" title="Pointer to binary file.">fd</a>, <span class="keywordtype">int</span> offset)
<a name="l00077"></a>00077 {
<a name="l00078"></a>00078         <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> buf;
<a name="l00079"></a>00079         lseek(fd, shdr.sh_offset + offset, SEEK_SET);
<a name="l00080"></a>00080         read(fd, &amp;buf, 1);
<a name="l00081"></a>00081         <span class="keywordflow">return</span> buf;
<a name="l00082"></a>00082 }
<a name="l00091"></a><a class="code" href="header_process_8c.html#a8e4ad65b0ee0fe343882d85d093b7759">00091</a> <span class="keywordtype">char</span> <a class="code" href="header_process_8c.html#a8e4ad65b0ee0fe343882d85d093b7759">readBinHeaderData</a>(GElf_Shdr shdr, <span class="keywordtype">int</span> <a class="code" href="my_obj_dump_8c.html#a6f8059414f0228f0256115e024eeed4b" title="Pointer to binary file.">fd</a>, <span class="keywordtype">int</span> offset, <span class="keywordtype">char</span>* buf, <span class="keywordtype">char</span> <a class="code" href="my_obj_dump_8c.html#a1e1268d164c38e4f8a4f4eb9058b0601" title="File size.">size</a>)
<a name="l00092"></a>00092 {
<a name="l00093"></a>00093         lseek(fd, shdr.sh_offset + offset, SEEK_SET);
<a name="l00094"></a>00094         read(fd, buf, size);
<a name="l00095"></a>00095         <span class="keywordflow">return</span> <a class="code" href="debug_8h.html#ae56fdb340b23940f7a64ed2e37c1774a" title="Response code when a process has performed an error in its execution.">STATUS_SUCCESS</a>;
<a name="l00096"></a>00096 }
<a name="l00102"></a><a class="code" href="header_process_8c.html#afaf18ccf41a8fab748ba6cb0adb5c319">00102</a> <span class="keywordtype">char</span> <a class="code" href="header_process_8c.html#afaf18ccf41a8fab748ba6cb0adb5c319" title="Sets the hex output format to the readBinHeaderByte function.">rawPrintContent</a>(<span class="keywordtype">int</span> <a class="code" href="my_obj_dump_8c.html#a6f8059414f0228f0256115e024eeed4b" title="Pointer to binary file.">fd</a>, GElf_Shdr shdr)
<a name="l00103"></a>00103 {
<a name="l00104"></a>00104         <span class="keywordtype">char</span> tCount = <a class="code" href="header_process_8c.html#a3c0994146b1bef939dee3fe64f6dce28" title="Raw print length.">RAW_PRINT_LENGTH</a>;
<a name="l00105"></a>00105         <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> p = 0;
<a name="l00106"></a>00106         <span class="keywordflow">while</span> (p &lt; shdr.sh_size)
<a name="l00107"></a>00107         {
<a name="l00108"></a>00108                 tCount--;
<a name="l00109"></a>00109                 <span class="keywordflow">if</span> (tCount)
<a name="l00110"></a>00110                 {
<a name="l00111"></a>00111                         printf(<span class="stringliteral">&quot;%02x &quot;</span>, <a class="code" href="header_process_8c.html#ad24288bd8f64a0089255ac61b93c4ecb" title="Reads the binary contents of a byte of section established.">readBinHeaderByte</a>(shdr, fd, p));
<a name="l00112"></a>00112                 }
<a name="l00113"></a>00113                 <span class="keywordflow">else</span>
<a name="l00114"></a>00114                 {
<a name="l00115"></a>00115                         printf(<span class="stringliteral">&quot;%02x \n&quot;</span>, <a class="code" href="header_process_8c.html#ad24288bd8f64a0089255ac61b93c4ecb" title="Reads the binary contents of a byte of section established.">readBinHeaderByte</a>(shdr, fd, p));
<a name="l00116"></a>00116                         tCount = <a class="code" href="header_process_8c.html#a3c0994146b1bef939dee3fe64f6dce28" title="Raw print length.">RAW_PRINT_LENGTH</a>;
<a name="l00117"></a>00117                 }
<a name="l00118"></a>00118                 p++;
<a name="l00119"></a>00119         }
<a name="l00120"></a>00120         printf(<span class="stringliteral">&quot;\n&quot;</span>);
<a name="l00121"></a>00121         <span class="keywordflow">return</span> <a class="code" href="debug_8h.html#ae56fdb340b23940f7a64ed2e37c1774a" title="Response code when a process has performed an error in its execution.">STATUS_SUCCESS</a>;
<a name="l00122"></a>00122 }
<a name="l00127"></a><a class="code" href="header_process_8c.html#a3cf7c204025d9fb0a86031ffdd481992">00127</a> <span class="keywordtype">void</span> <a class="code" href="header_process_8c.html#a3cf7c204025d9fb0a86031ffdd481992" title="Sets output format to a machine instruction.">printMachinePretty</a>(<a class="code" href="struct___machine_inst_format.html" title="Machine Instruction Format.">MACHINE_INSTRUCTION</a> * inst)
<a name="l00128"></a>00128 {
<a name="l00129"></a>00129         <a class="code" href="common_8h.html#ad8ce12d83f204245685f98caf9d03944" title="One byte.">UINT8</a> * opPtr;
<a name="l00130"></a>00130         <a class="code" href="common_8h.html#ad8ce12d83f204245685f98caf9d03944" title="One byte.">UINT8</a> * isOpPtr;
<a name="l00131"></a>00131         <a class="code" href="common_8h.html#ad8ce12d83f204245685f98caf9d03944" title="One byte.">UINT8</a> * isOpValid;
<a name="l00132"></a>00132         <a class="code" href="common_8h.html#ad8ce12d83f204245685f98caf9d03944" title="One byte.">UINT8</a> counter = <a class="code" href="common_8h.html#a22613dfae1a9dc932b6a4513895411c9" title="supported number of operators">NUM_OPP_SUPPORTED</a>;
<a name="l00133"></a>00133         <a class="code" href="common_8h.html#ad8ce12d83f204245685f98caf9d03944" title="One byte.">UINT8</a> opNumber = 0;
<a name="l00134"></a>00134 
<a name="l00135"></a>00135 
<a name="l00136"></a>00136         printf(<span class="stringliteral">&quot;-------------------INSTRUCTION---------------\n&quot;</span>);
<a name="l00137"></a>00137         printf(<span class="stringliteral">&quot;Menemonic: %s\n&quot;</span>, inst-&gt;<a class="code" href="struct___machine_inst_format.html#a6828a502ed446152add8bca7a42d0d09" title="mnemonic">mnemonic</a>);
<a name="l00138"></a>00138         printf(<span class="stringliteral">&quot;Opcode: %x\n&quot;</span>, inst-&gt;<a class="code" href="struct___machine_inst_format.html#afb7ad97a332968900eaa5c855884032b" title="Operation Code.">opcode</a>.<a class="code" href="union__opcode.html#a537893029f1863ac865b24ec727c24b8" title="Operation code value.">value</a>);
<a name="l00139"></a>00139 
<a name="l00140"></a>00140 
<a name="l00141"></a>00141         <span class="keywordflow">if</span> (inst-&gt;<a class="code" href="struct___machine_inst_format.html#a53e89f0766181e3cfb8ec3b314f437ef" title="Prefix value.">isPrefix</a>) <span class="comment">//Identifies if the instruction is a prefix</span>
<a name="l00142"></a>00142         {
<a name="l00143"></a>00143                 printf(<span class="stringliteral">&quot;Prefix: %x\n&quot;</span>, (<a class="code" href="common_8h.html#ad8ce12d83f204245685f98caf9d03944" title="One byte.">UINT8</a>) inst-&gt;<a class="code" href="struct___machine_inst_format.html#a42f928fa90cd801945bf61b59cb49e92">prefix</a>.<a class="code" href="struct__prefix.html#a537893029f1863ac865b24ec727c24b8">value</a>);
<a name="l00144"></a>00144         }
<a name="l00145"></a>00145         <span class="keywordflow">if</span>(inst-&gt;<a class="code" href="struct___machine_inst_format.html#af2cf9d902e06474e4cbcf47c1cdc6bfc" title="If it is a ModReg register.">isModeReg</a>) <span class="comment">//Identifies if the instruction has a modeReg register</span>
<a name="l00146"></a>00146         {
<a name="l00147"></a>00147                 printf(<span class="stringliteral">&quot;ModReg: %x\n&quot;</span>, (<a class="code" href="common_8h.html#ad8ce12d83f204245685f98caf9d03944" title="One byte.">UINT8</a>)inst-&gt;<a class="code" href="struct___machine_inst_format.html#ab59debee789b0be0ca71811fe2b5080f">mod_reg_rm</a>.<a class="code" href="union__mod__reg.html#a537893029f1863ac865b24ec727c24b8">value</a>);
<a name="l00148"></a>00148         }
<a name="l00149"></a>00149 
<a name="l00150"></a>00150 
<a name="l00151"></a>00151         isOpPtr = inst-&gt;<a class="code" href="struct___machine_inst_format.html#a677fc789ef02b6679c3ed09d452b91b4" title="Operation Code Size.">opSize</a>;
<a name="l00152"></a>00152         isOpValid = inst-&gt;<a class="code" href="struct___machine_inst_format.html#a31057fc58f4b612b1619cbb4f3c4b979" title="If it is an operation code valid.">opValid</a>;
<a name="l00153"></a>00153         <span class="keywordflow">while</span>(counter)
<a name="l00154"></a>00154         {
<a name="l00155"></a>00155                 opPtr = inst-&gt;<a class="code" href="struct___machine_inst_format.html#a4eb58e92677c4abf81b67f89d36b3b3d" title="Operation Code.">op</a>[opNumber];
<a name="l00156"></a>00156                 <span class="keywordflow">if</span>(*isOpValid)
<a name="l00157"></a>00157                 {
<a name="l00158"></a>00158                         <a class="code" href="common_8h.html#ad8ce12d83f204245685f98caf9d03944" title="One byte.">UINT8</a> opByte = 0;
<a name="l00159"></a>00159 
<a name="l00160"></a>00160                         printf(<span class="stringliteral">&quot;Operand[%x]: &quot;</span>,opNumber);
<a name="l00161"></a>00161 
<a name="l00162"></a>00162                         <a class="code" href="common_8h.html#ad8ce12d83f204245685f98caf9d03944" title="One byte.">UINT8</a> opSize = <a class="code" href="common_8h.html#a4aa5e2926d1ef8bcce281e0eab30025a" title="One byte in binary.">BIT2BYTE</a>(inst-&gt;<a class="code" href="struct___machine_inst_format.html#a677fc789ef02b6679c3ed09d452b91b4" title="Operation Code Size.">opSize</a>[counter]);
<a name="l00163"></a>00163 
<a name="l00164"></a>00164                         <span class="keywordflow">while</span>(opSize)
<a name="l00165"></a>00165                         {
<a name="l00166"></a>00166                                 printf(<span class="stringliteral">&quot;%02x &quot;</span>,opPtr[opByte]);
<a name="l00167"></a>00167                                 opSize--;
<a name="l00168"></a>00168                                 opByte++;
<a name="l00169"></a>00169                         }
<a name="l00170"></a>00170                         printf(<span class="stringliteral">&quot;\n&quot;</span>);
<a name="l00171"></a>00171                 }
<a name="l00172"></a>00172 
<a name="l00173"></a>00173 
<a name="l00174"></a>00174                 opNumber++;
<a name="l00175"></a>00175                 isOpValid++;
<a name="l00176"></a>00176                 opPtr++;
<a name="l00177"></a>00177                 isOpPtr++;
<a name="l00178"></a>00178                 counter--;
<a name="l00179"></a>00179         }
<a name="l00180"></a>00180 
<a name="l00181"></a>00181         printf(<span class="stringliteral">&quot;--------------------------------------------\n&quot;</span>);
<a name="l00182"></a>00182 }
<a name="l00183"></a>00183 
<a name="l00188"></a><a class="code" href="header_process_8c.html#acc4eb4e80b0bee5ee1867ffa7b5069a1">00188</a> <span class="keywordtype">void</span> <a class="code" href="header_process_8c.html#acc4eb4e80b0bee5ee1867ffa7b5069a1" title="Displays the hexadecimal number for the instruction processed.">printMachine</a>(<a class="code" href="struct___machine_inst_format.html" title="Machine Instruction Format.">MACHINE_INSTRUCTION</a> * inst)
<a name="l00189"></a>00189 {
<a name="l00190"></a>00190         <a class="code" href="common_8h.html#ad8ce12d83f204245685f98caf9d03944" title="One byte.">UINT8</a> * opPtr;
<a name="l00191"></a>00191         <a class="code" href="common_8h.html#ad8ce12d83f204245685f98caf9d03944" title="One byte.">UINT8</a> * isOpPtr;
<a name="l00192"></a>00192         <a class="code" href="common_8h.html#ad8ce12d83f204245685f98caf9d03944" title="One byte.">UINT8</a> * isOpValid;
<a name="l00193"></a>00193         <a class="code" href="common_8h.html#ad8ce12d83f204245685f98caf9d03944" title="One byte.">UINT8</a> counter = <a class="code" href="common_8h.html#a22613dfae1a9dc932b6a4513895411c9" title="supported number of operators">NUM_OPP_SUPPORTED</a>;
<a name="l00194"></a>00194         <a class="code" href="common_8h.html#ad8ce12d83f204245685f98caf9d03944" title="One byte.">UINT8</a> opNumber = 0;
<a name="l00195"></a>00195 
<a name="l00196"></a>00196         <span class="keywordflow">if</span> (inst-&gt;<a class="code" href="struct___machine_inst_format.html#a53e89f0766181e3cfb8ec3b314f437ef" title="Prefix value.">isPrefix</a>)
<a name="l00197"></a>00197         {
<a name="l00198"></a>00198                 printf(<span class="stringliteral">&quot;%02x &quot;</span>, (<a class="code" href="common_8h.html#ad8ce12d83f204245685f98caf9d03944" title="One byte.">UINT8</a>) inst-&gt;<a class="code" href="struct___machine_inst_format.html#a42f928fa90cd801945bf61b59cb49e92">prefix</a>.<a class="code" href="struct__prefix.html#a537893029f1863ac865b24ec727c24b8">value</a>);
<a name="l00199"></a>00199         }
<a name="l00200"></a>00200         printf(<span class="stringliteral">&quot;%02x &quot;</span>, inst-&gt;<a class="code" href="struct___machine_inst_format.html#afb7ad97a332968900eaa5c855884032b" title="Operation Code.">opcode</a>.<a class="code" href="union__opcode.html#a537893029f1863ac865b24ec727c24b8" title="Operation code value.">value</a>);
<a name="l00201"></a>00201 
<a name="l00202"></a>00202         <span class="keywordflow">if</span> (inst-&gt;<a class="code" href="struct___machine_inst_format.html#af2cf9d902e06474e4cbcf47c1cdc6bfc" title="If it is a ModReg register.">isModeReg</a>)
<a name="l00203"></a>00203         {
<a name="l00204"></a>00204                 printf(<span class="stringliteral">&quot;%x &quot;</span>, (<a class="code" href="common_8h.html#ad8ce12d83f204245685f98caf9d03944" title="One byte.">UINT8</a>) inst-&gt;<a class="code" href="struct___machine_inst_format.html#ab59debee789b0be0ca71811fe2b5080f">mod_reg_rm</a>.<a class="code" href="union__mod__reg.html#a537893029f1863ac865b24ec727c24b8">value</a>);
<a name="l00205"></a>00205         }
<a name="l00206"></a>00206 
<a name="l00207"></a>00207         isOpPtr = inst-&gt;<a class="code" href="struct___machine_inst_format.html#a677fc789ef02b6679c3ed09d452b91b4" title="Operation Code Size.">opSize</a>;
<a name="l00208"></a>00208         isOpValid = inst-&gt;<a class="code" href="struct___machine_inst_format.html#a31057fc58f4b612b1619cbb4f3c4b979" title="If it is an operation code valid.">opValid</a>;
<a name="l00209"></a>00209         <span class="keywordflow">while</span>(counter)
<a name="l00210"></a>00210         {
<a name="l00211"></a>00211                 opPtr = inst-&gt;<a class="code" href="struct___machine_inst_format.html#a4eb58e92677c4abf81b67f89d36b3b3d" title="Operation Code.">op</a>[opNumber];
<a name="l00212"></a>00212                 <span class="keywordflow">if</span>(*isOpValid)
<a name="l00213"></a>00213                 {
<a name="l00214"></a>00214                         <a class="code" href="common_8h.html#ad8ce12d83f204245685f98caf9d03944" title="One byte.">UINT8</a> opByte = 0;
<a name="l00215"></a>00215                         <a class="code" href="common_8h.html#ad8ce12d83f204245685f98caf9d03944" title="One byte.">UINT8</a> opSize = <a class="code" href="common_8h.html#a4aa5e2926d1ef8bcce281e0eab30025a" title="One byte in binary.">BIT2BYTE</a>(inst-&gt;<a class="code" href="struct___machine_inst_format.html#a677fc789ef02b6679c3ed09d452b91b4" title="Operation Code Size.">opSize</a>[counter]);
<a name="l00216"></a>00216 
<a name="l00217"></a>00217                         <span class="keywordflow">while</span>(opSize)
<a name="l00218"></a>00218                         {
<a name="l00219"></a>00219                                 printf(<span class="stringliteral">&quot;%02x &quot;</span>,opPtr[opByte]);
<a name="l00220"></a>00220                                 opSize--;
<a name="l00221"></a>00221                                 opByte++;
<a name="l00222"></a>00222                         }
<a name="l00223"></a>00223 
<a name="l00224"></a>00224                 }
<a name="l00225"></a>00225                 <span class="keywordflow">else</span>
<a name="l00226"></a>00226                 {
<a name="l00227"></a>00227 
<a name="l00228"></a>00228                 }
<a name="l00229"></a>00229 
<a name="l00230"></a>00230 
<a name="l00231"></a>00231                 opNumber++;
<a name="l00232"></a>00232                 isOpValid++;
<a name="l00233"></a>00233                 opPtr++;
<a name="l00234"></a>00234                 isOpPtr++;
<a name="l00235"></a>00235                 counter--;
<a name="l00236"></a>00236         }
<a name="l00237"></a>00237         <span class="comment">//printf(&quot;\n&quot;);</span>
<a name="l00238"></a>00238 }
<a name="l00243"></a><a class="code" href="header_process_8c.html#a3be427673484ac076b7513861e5dc3bc">00243</a> <span class="keywordtype">void</span> <a class="code" href="header_process_8c.html#a3be427673484ac076b7513861e5dc3bc" title="Displays the assembler instruction corresponding to the instruction analyzed.">printAsm</a>(<a class="code" href="struct___machine_inst_format.html" title="Machine Instruction Format.">MACHINE_INSTRUCTION</a> * inst)
<a name="l00244"></a>00244 {
<a name="l00245"></a>00245 
<a name="l00246"></a>00246         <a class="code" href="common_8h.html#ad8ce12d83f204245685f98caf9d03944" title="One byte.">UINT8</a> opNumber = 0;
<a name="l00247"></a>00247 
<a name="l00248"></a>00248 
<a name="l00249"></a>00249         <span class="comment">//</span>
<a name="l00250"></a>00250         <span class="comment">//Print ASM</span>
<a name="l00251"></a>00251         <span class="comment">//</span>
<a name="l00252"></a>00252         printf(<span class="stringliteral">&quot;%s &quot;</span>, inst-&gt;<a class="code" href="struct___machine_inst_format.html#a6828a502ed446152add8bca7a42d0d09" title="mnemonic">mnemonic</a>);
<a name="l00253"></a>00253 
<a name="l00254"></a>00254 
<a name="l00255"></a>00255         opNumber = 0;
<a name="l00256"></a>00256 
<a name="l00257"></a>00257         <span class="keywordflow">while</span>(opNumber &lt; <a class="code" href="common_8h.html#a22613dfae1a9dc932b6a4513895411c9" title="supported number of operators">NUM_OPP_SUPPORTED</a>)
<a name="l00258"></a>00258         {
<a name="l00259"></a>00259                 <span class="keywordflow">if</span>(inst-&gt;<a class="code" href="struct___machine_inst_format.html#af2c2ded7b07967b789041120b1ab496e">regOpValid</a>[opNumber])
<a name="l00260"></a>00260                 {
<a name="l00261"></a>00261                         printf(<span class="stringliteral">&quot;%s &quot;</span>, inst-&gt;<a class="code" href="struct___machine_inst_format.html#ad584458f2e8f530ffd6b90449da4c915">regOpp</a>[opNumber]);
<a name="l00262"></a>00262                 }
<a name="l00263"></a>00263                 opNumber++;
<a name="l00264"></a>00264         }
<a name="l00265"></a>00265 
<a name="l00266"></a>00266         opNumber = 0;
<a name="l00267"></a>00267         <span class="keywordflow">while</span>(opNumber &lt; <a class="code" href="common_8h.html#a22613dfae1a9dc932b6a4513895411c9" title="supported number of operators">NUM_OPP_SUPPORTED</a>)
<a name="l00268"></a>00268         {
<a name="l00269"></a>00269                 <span class="keywordflow">if</span>(inst-&gt;<a class="code" href="struct___machine_inst_format.html#a31057fc58f4b612b1619cbb4f3c4b979" title="If it is an operation code valid.">opValid</a>[opNumber])
<a name="l00270"></a>00270                 {
<a name="l00271"></a>00271                         <a class="code" href="common_8h.html#ad8ce12d83f204245685f98caf9d03944" title="One byte.">UINT8</a> opByte = 0;
<a name="l00272"></a>00272                         <a class="code" href="common_8h.html#ad8ce12d83f204245685f98caf9d03944" title="One byte.">UINT8</a> opSize = <a class="code" href="common_8h.html#a4aa5e2926d1ef8bcce281e0eab30025a" title="One byte in binary.">BIT2BYTE</a>(inst-&gt;<a class="code" href="struct___machine_inst_format.html#a677fc789ef02b6679c3ed09d452b91b4" title="Operation Code Size.">opSize</a>[opNumber]);
<a name="l00273"></a>00273                         printf(<span class="stringliteral">&quot;$&quot;</span>);
<a name="l00274"></a>00274                         <span class="keywordflow">while</span> (opSize)
<a name="l00275"></a>00275                         {
<a name="l00276"></a>00276                                 printf(<span class="stringliteral">&quot;%02x&quot;</span>, inst-&gt;<a class="code" href="struct___machine_inst_format.html#a4eb58e92677c4abf81b67f89d36b3b3d" title="Operation Code.">op</a>[opNumber][opByte]);
<a name="l00277"></a>00277                                 opSize--;
<a name="l00278"></a>00278                                 opByte++;
<a name="l00279"></a>00279                         }
<a name="l00280"></a>00280                 }
<a name="l00281"></a>00281                 opNumber++;
<a name="l00282"></a>00282         }
<a name="l00283"></a>00283 
<a name="l00284"></a>00284         <span class="comment">//printf(&quot;\n&quot;);</span>
<a name="l00285"></a>00285 }
<a name="l00293"></a><a class="code" href="header_process_8c.html#a9832a2fd05088ded2ec732fa0656dfca">00293</a> <span class="keywordtype">char</span> <a class="code" href="header_process_8c.html#a9832a2fd05088ded2ec732fa0656dfca" title="Function that processes the text contained within a section of the file.">processText</a>(GElf_Shdr shdr, Elf* e, <span class="keywordtype">size_t</span> shstrndx, <span class="keywordtype">int</span> <a class="code" href="my_obj_dump_8c.html#a6f8059414f0228f0256115e024eeed4b" title="Pointer to binary file.">fd</a>)
<a name="l00294"></a>00294 {
<a name="l00295"></a>00295         <span class="keywordtype">char</span> *name;
<a name="l00296"></a>00296         <a class="code" href="common_8h.html#ad8ce12d83f204245685f98caf9d03944" title="One byte.">UINT8</a> decodedSize = 0;
<a name="l00297"></a>00297         Elf_Scn *scn;
<a name="l00298"></a>00298         <span class="comment">//todo debug offset</span>
<a name="l00299"></a>00299 
<a name="l00300"></a>00300         <a class="code" href="common_8h.html#a69afa2e50b905f4eab1f2df8a3fd9f23" title="One instruction.">UINT32</a> offset = 0x00;
<a name="l00301"></a>00301         <span class="keywordtype">char</span> buf[<a class="code" href="config_8h.html#ac27ae7cd587f7c629d5f29c03ca59e46" title="Max Instruction length.">MAX_INSTRUCTION_LENGTH</a>];
<a name="l00302"></a>00302         <a class="code" href="struct___machine_inst_format.html" title="Machine Instruction Format.">MACHINE_INSTRUCTION</a> currentInstruction;
<a name="l00303"></a>00303         scn = NULL ;
<a name="l00304"></a>00304         <span class="keywordflow">while</span> ((scn=elf_nextscn(e,scn))!=NULL)
<a name="l00305"></a>00305         {
<a name="l00306"></a>00306                 <span class="keywordflow">if</span> (gelf_getshdr(scn,&amp;shdr)!=&amp;shdr)
<a name="l00307"></a>00307                         <a class="code" href="debug_8c.html#a8ded31085b483d44dbeb3adbecd2debf" title="Displays the error message.">PRINT_ERROR</a>( <span class="stringliteral">&quot;getshdr() failed: %s.&quot;</span> ,elf_errmsg ( -1));
<a name="l00308"></a>00308                 <span class="keywordflow">if</span> ((name = elf_strptr(e, shstrndx, shdr.sh_name)) == NULL )
<a name="l00309"></a>00309                 {
<a name="l00310"></a>00310                         <a class="code" href="debug_8c.html#a8ded31085b483d44dbeb3adbecd2debf" title="Displays the error message.">PRINT_ERROR</a>(<span class="stringliteral">&quot;elf_strptr () failed : % s . &quot;</span>, elf_errmsg(-1));
<a name="l00311"></a>00311                         <span class="keywordflow">return</span> <a class="code" href="debug_8h.html#ae4a97f0d170bc8dc771aac6c4f38ad1d" title="Response code when a process was run efficiently.">STATUS_ERROR</a>;
<a name="l00312"></a>00312                 }
<a name="l00313"></a>00313                 printf(<span class="stringliteral">&quot;Section: %s size: %x\n&quot;</span>,name,(<a class="code" href="common_8h.html#ad8ce12d83f204245685f98caf9d03944" title="One byte.">UINT8</a>)shdr.sh_size);
<a name="l00314"></a>00314                 <a class="code" href="debug_8h.html#a1b7e26bb727a722ca100ed856b4e1d98" title="Print Debug.">PRINT_DEBUG</a>(<a class="code" href="debug_8h.html#a36e70ecf5c28440bbbc51209f8525cd8" title="Debug ELF header process.">DEBUG_ELF_HEADER_PROCESS</a>, <span class="stringliteral">&quot;Processing %s...\n&quot;</span>, name);
<a name="l00315"></a>00315                 <a class="code" href="debug_8h.html#a1b7e26bb727a722ca100ed856b4e1d98" title="Print Debug.">PRINT_DEBUG</a>(<a class="code" href="debug_8h.html#a36e70ecf5c28440bbbc51209f8525cd8" title="Debug ELF header process.">DEBUG_ELF_HEADER_PROCESS</a>, <span class="stringliteral">&quot;   size %x\n&quot;</span>, (<a class="code" href="common_8h.html#ad8ce12d83f204245685f98caf9d03944" title="One byte.">UINT8</a>)shdr.sh_size);
<a name="l00316"></a>00316                 <a class="code" href="debug_8h.html#a1b7e26bb727a722ca100ed856b4e1d98" title="Print Debug.">PRINT_DEBUG</a>(<a class="code" href="debug_8h.html#a36e70ecf5c28440bbbc51209f8525cd8" title="Debug ELF header process.">DEBUG_ELF_HEADER_PROCESS</a>, <span class="stringliteral">&quot;   offs %x\n&quot;</span>, (<a class="code" href="common_8h.html#ad8ce12d83f204245685f98caf9d03944" title="One byte.">UINT8</a>)shdr.sh_offset);
<a name="l00317"></a>00317 
<a name="l00318"></a>00318                 <span class="keywordflow">while</span> (offset &lt; shdr.sh_size)
<a name="l00319"></a>00319                 {
<a name="l00320"></a>00320                         <a class="code" href="my_lib_8c.html#ad999555d5a1145e88b750ad0fc42f8b2" title="Empty memory.">zeromem</a>(&amp;currentInstruction, <span class="keyword">sizeof</span>(<a class="code" href="struct___machine_inst_format.html" title="Machine Instruction Format.">MACHINE_INSTRUCTION</a>));
<a name="l00321"></a>00321                         <a class="code" href="header_process_8c.html#a8e4ad65b0ee0fe343882d85d093b7759">readBinHeaderData</a>(shdr, fd, offset, buf, (<a class="code" href="common_8h.html#a7e125472d65b57f10905accbed140b99" title="Stores 8 bits.">INT8</a>) <a class="code" href="config_8h.html#ac27ae7cd587f7c629d5f29c03ca59e46" title="Max Instruction length.">MAX_INSTRUCTION_LENGTH</a>);
<a name="l00322"></a>00322                         <a class="code" href="debug_8h.html#a1b7e26bb727a722ca100ed856b4e1d98" title="Print Debug.">PRINT_DEBUG</a>(<a class="code" href="debug_8h.html#afb7d6d1394874eb9a80612633f0256ef" title="Debug next instruction.">DEBUG_DECODE_NEXT_INSTRUCTION</a>,
<a name="l00323"></a>00323                                                 <span class="stringliteral">&quot;$$$%08x:%02x\n&quot;</span>,
<a name="l00324"></a>00324                                                 offset, (<a class="code" href="common_8h.html#ad8ce12d83f204245685f98caf9d03944" title="One byte.">UINT8</a>)*buf);
<a name="l00325"></a>00325                         <a class="code" href="decode_8c.html#a3297beb269c3c0ed6a8e226861488785" title="State machine that controls the disassembly process.">decode</a>(buf, &amp;decodedSize, &amp;currentInstruction);
<a name="l00326"></a>00326 
<a name="l00327"></a>00327                         <a class="code" href="debug_8h.html#a1b7e26bb727a722ca100ed856b4e1d98" title="Print Debug.">PRINT_DEBUG</a>(<a class="code" href="debug_8h.html#a41d588ee907c299c7a790964deeef02d" title="Debug all process.">DEBUG_ALL</a>, <span class="stringliteral">&quot;SIZE : %x\n&quot;</span>, decodedSize);
<a name="l00328"></a>00328                         printf(<span class="stringliteral">&quot;$%08x: &quot;</span>,offset);
<a name="l00329"></a>00329                         <a class="code" href="header_process_8c.html#acc4eb4e80b0bee5ee1867ffa7b5069a1" title="Displays the hexadecimal number for the instruction processed.">printMachine</a>(&amp;currentInstruction);
<a name="l00330"></a>00330                         <a class="code" href="header_process_8c.html#a3be427673484ac076b7513861e5dc3bc" title="Displays the assembler instruction corresponding to the instruction analyzed.">printAsm</a>(&amp;currentInstruction);
<a name="l00331"></a>00331                         printf(<span class="stringliteral">&quot;\n&quot;</span>);
<a name="l00332"></a>00332                         <span class="comment">//printMachine(&amp;currentInstruction);</span>
<a name="l00333"></a>00333 
<a name="l00334"></a>00334                         offset += decodedSize;
<a name="l00335"></a>00335                 }
<a name="l00336"></a>00336 
<a name="l00337"></a>00337         }
<a name="l00338"></a>00338         <span class="keywordflow">return</span> <a class="code" href="debug_8h.html#ae56fdb340b23940f7a64ed2e37c1774a" title="Response code when a process has performed an error in its execution.">STATUS_SUCCESS</a>;
<a name="l00339"></a>00339 }
</pre></div></div><!-- contents -->
</div>
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
<a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(0)"><span class="SelectionMark">&#160;</span>All</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(1)"><span class="SelectionMark">&#160;</span>Data Structures</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(2)"><span class="SelectionMark">&#160;</span>Files</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(3)"><span class="SelectionMark">&#160;</span>Functions</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(4)"><span class="SelectionMark">&#160;</span>Variables</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(5)"><span class="SelectionMark">&#160;</span>Typedefs</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(6)"><span class="SelectionMark">&#160;</span>Enumerations</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(7)"><span class="SelectionMark">&#160;</span>Enumerator</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(8)"><span class="SelectionMark">&#160;</span>Defines</a></div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

  <div id="nav-path" class="navpath">
    <ul>
      <li class="navelem"><a class="el" href="header_process_8c.html">headerProcess.c</a>      </li>

    <li class="footer">Generated on Thu Oct 11 2012 12:28:10 for Dissasemble by
    <a href="http://www.doxygen.org/index.html">
    <img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.7.6.1 </li>
   </ul>
 </div>


</body>
</html>
